;
(function (call) {
    var main = {
        userInfo: null,
        mapId: "jcybMap",
        init: function () {
            this.initView();
            this.bindEvt();
        },
        initView: function () {
            this.initPublishMeans();
            var time = $("#datepicker .datepicker-date span").text()
            var endTime = new Date(time).format("yyyy-MM-dd hh:mm");
            var startTime = new Date(endTime);
            startTime.setHours(startTime.getHours() - 24);
            startTime = startTime.format("yyyy-MM-dd hh:mm");
            // 预警产品时间控件
            this.startTime = CafeJS.Datepicker({
                appendTo: "#startMonitorTime",
                type: 1,
                dateFmt: "yyyy-MM-dd hh:mm",
                curDate: startTime
            });
            this.endTime = CafeJS.Datepicker({
                appendTo: "#endMonitorTime",
                type: 1,
                dateFmt: "yyyy-MM-dd hh:mm",
                curDate: endTime
            });
            // 其他监控时间
            this.startTime2 = CafeJS.Datepicker({
                appendTo: "#startMonitorTime2",
                type: 1,
                dateFmt: "yyyy-MM-dd hh:mm",
                curDate: startTime
            });
            this.endTime2 = CafeJS.Datepicker({
                appendTo: "#endMonitorTime2",
                type: 1,
                dateFmt: "yyyy-MM-dd hh:mm",
                curDate: endTime
            });
            // 三级防御监控时间
            this.startTime2 = CafeJS.Datepicker({
                appendTo: "#startThreejkTime2",
                type: 1,
                dateFmt: "yyyy-MM-dd hh:mm",
                curDate: startTime
            });
            this.endTime2 = CafeJS.Datepicker({
                appendTo: "#endThreejkTime2",
                type: 1,
                dateFmt: "yyyy-MM-dd hh:mm",
                curDate: endTime
            });
            //  叫应监控时间
            this.startTime3 = CafeJS.Datepicker({
                appendTo: "#startMonitorTime3",
                type: 1,
                dateFmt: "yyyy-MM-dd hh:mm",
                curDate: startTime
            });
            var newDate = new Date(time);
            newDate.setMinutes(newDate.getMinutes() + 30);
            endTime = newDate.format('yyyy-MM-dd hh:mm');
            this.endTime3 = CafeJS.Datepicker({
                appendTo: "#endMonitorTime3",
                type: 1,
                dateFmt: "yyyy-MM-dd hh:mm",
                curDate: endTime
            });
            $("#modal_monitor").find("#modal-title span").first().click();
            this.getUserOrgsData();
            this.getAreaSelectList();
        },
        // 初始化发布手段
        initPublishMeans: function () {
            $.getJSON(api.internal.business.getpublishMeansData, function (res) {
                var $publishMeans = $("#publishMeans");
                if (res.isSuccess) {
                    for (var key in res.data) {
                        var $option = $(`<option value="${key}">${res.data[key]}</option>`);
                        $publishMeans.append($option);
                    }
                }
            })
        },
        // 获取预警信号发布总数
        getAlertCount: function(params) {
			$.ajax({
                url: api.external.getAlertCount,
                type: "POST",
                contentType: "application/json;charset=utf-8",
                dataType: 'json',
                data: JSON.stringify(params),
                success: function (res) {
					if (res.FBInfo && res.FBInfo.length > 0) {
						var publishTotal = Number(res.FBInfo[0].successCount) + Number(res.FBInfo[0].failCount);
						$(".publishTotal").text(publishTotal);
						var successRate = ((res.FBInfo[0].successCount / publishTotal) * 100).toFixed(2)
						$(".successRate").text(successRate == 'NaN' ? '0%' : successRate + '%')
					}
                }
            })
        },
        publishDetailsPop: function (data) {
            CafeJS.ModalBox({
                id: 'publish_details',
                title: "发布详情",
                width: 800,
                height: 480,
                m_top: 270,
                m_right: 270,
                hide: false,
                header: false,
                isBackdrop: true,
                url: api.internal.tpl.publishDetails
            });
            $("#modal_publish_details").data('dataObj', data);
        },
        // 构建表头
        buildTableHeader: function () {
            var productType = $("#productType").val();
            var $head = $(".alarm-header").empty();
            var $div = '<div style="width: 5%">序号</div><div>产品类型</div><div>产品名称</div>'
            if (productType == 'yjxh') {
                $div += '<div>推送时间</div>'
            } else {
                $div += '<div>制作时间</div>'
            }
            $div += '<div>制作人</div>'
            if (productType == 'yjxh') {
                $div += '<div>单位</div>'
            } else {
                $div += '<div>签发人</div>'
            }
            if (productType == 'yjxh') {
                $div += '<div>录入人</div><div>审核人</div><div>发布时间</div>'
            }
            $div += '<div>发布手段</div><div>发布详情</div>'
            if (productType == 'jcfw') {
                $div += '<div>成功率</div>'
            }
            if (productType == 'yjxh') {
                $div += '<div>是否及时</div>'
            }
            $head.append($div);
            $(".alarm-header div").slice(1).css('width', 95 / 8 + "%");
            if (productType == 'yjxh') {
                $(".alarm-header div").slice(1).css('width', 74 / 9 + "%");
                $(".alarm-header div").eq(3).css('width', "10.5%");
                $(".alarm-header div").eq(8).css('width', "10.5%");
            }
        },
        // 组装数据
        getTableData: function () {
            var that = this;
            $(".alarm-body").empty();
            var productType = $("#productType").val();
            var publishUnit = $("#productUnitSelect").val();
            var params = {};
            if (productType == 'jcfw') {
                params = {
                    startTime: new Date(that.startTime.getVal() + ":00").format('yyyyMMddhhmmss'),
                    endTime: new Date(that.endTime.getVal()).format('yyyyMMddhhmmss')
                }
                loading.add('#modal_monitor');
                $.getJSON(api.external.queryJcfwData, params, function (res) {
                    loading.remove();
                    if (res.data) {
                        var data = res.data;
                        var modelData = [];
                        for (var i = 0; i < data.length; i++) {
                            var dataObj = data[i]
                            var obj = {}, details = [], styleName = [], publishSuccessRate = {}, publishSuccessCount = '', count = ''
                            for (var j = 0; j < dataObj.wayTypes.length; j++) {
                                var detailsObj = dataObj.wayTypes[j]
                                styleName.push(detailsObj.name)
                                for (var k = 0; k < detailsObj.sendDetails.length; k++) {
                                    details.push({
                                        STATUS: detailsObj.sendDetails[k].status,
                                        clientId: detailsObj.sendDetails[k].address,
                                        STYLE: detailsObj.name,
                                        publistDate: dateUtil.convertStringToDate1(detailsObj.sendDetails[k].sendTime)
                                    })
                                    if (detailsObj.sendDetails[k].status == '1') {
                                        publishSuccessCount++
                                    }
                                    count++
                                    publishSuccessRate = ((publishSuccessCount / count) * 100).toFixed(2)
                                }
                            }
                            if (!count) {
                                publishSuccessRate = ''
                            }
                            obj.details = details
                            obj.productName = dataObj.productName
                            obj.makeTime = dateUtil.convertStringToDate8(dataObj.createTime)
                            obj.makeUser = dataObj.creatorName
                            obj.issuerName = dataObj.issuerName
                            obj.styleName = styleName.join(',')
                            obj.publishSuccessRate = publishSuccessRate
                            obj.wordPath = dataObj.saveFileName + '.docx'
                            modelData.push(obj);
                        }
                        that.bulidTableInfo(modelData)
                    }
                })
            } else {
                params = {
                    starttime: that.startTime.getVal() + ":00",
                    endtime: that.endTime.getVal() + ":00",
                    districtCode: publishUnit,
                }
                loading.add('#modal_monitor');
				$.ajax({
					url: api.external.queryJkData,
					type: "POST",
					contentType: "application/json;charset=utf-8",
					dataType: 'json',
					data: JSON.stringify(params),
					success: function (res) {
						loading.remove();
						if (res.FBInfo) {
							var yjxhIds = res.FBInfo.map((info)=>{
								return info.Identifier;
							})
							$.post(api.internal.business.getMakerUserByYjxhIds, {yjxhIds: yjxhIds.join(',')}, function (res2) {
								if (res2.isSuccess) {
									res.FBInfo.forEach((data)=>{
										data.makeUser = res2.data[data.Identifier] ? res2.data[data.Identifier].makeUser : '';
										data.wordPath = res2.data[data.Identifier] ? res2.data[data.Identifier].wordPath : '';
									})
								}
								that.bulidTableInfo(res.FBInfo)
							}, 'json')
						}
					},
					error: function(){
						loading.remove();
					}
				})
                that.getAlertCount(params);
            }            
        },
        // 展示表格
        bulidTableInfo: function (data) {
            $(".productTotal").text(data.length)
            var productTypeName = $("#productType option:selected").text();
            var columnW = 95 / 8;
            if (productTypeName == '预警信号') {
                columnW = 74 / 9;
            }
            var domList = [], publishTotal = 0, publishSuccessCount = 0, timelyCount = 0;
            data.forEach(function (item, index) {
                var number = ++index;
				if (productTypeName != '预警信号') {
					publishTotal += item.details.length
					for (var i = 0; i < item.details.length; i++) {
						if (item.details[i].STATUS == '1') {
							publishSuccessCount++
						}
					}
					var success = item.publishSuccessRate
					if (success) {
						success = success + '%'
					}
				}
                var productName = item.productName == null ? '' : item.productName
                makeUser = item.makeUser == null ? '' : item.makeUser
                issuerName = item.issuerName == null ? '' : item.issuerName
                publisher = item.publisher == null ? '' : item.publisher
                auditUser = item.auditUser == null ? '' : item.auditUser
                styleName = item.styleName == null ? '' : item.styleName
                publishUnit = item.publishUnit == null ? '' : item.publishUnit
                publishDate = new Date(item.publishDate).format('yyyy-MM-dd hh:mm:ss')
                pushTime = new Date(item.pushTime).format('yyyy-MM-dd hh:mm:ss')
                d1 = Date.parse(publishDate.replace(/\-/g, "\/"))
                d2 = Date.parse(pushTime.replace(/\-/g, "\/"))
                var min = (d1 - d2) / 60000
                var content = '<div class="alarm-item">'
                content += '<div style="width: 5%">' + number + '</div>'
                content += '<div style="width: ' + columnW + '%">' + productTypeName + '</div>'
                content += '<div class="product-name" title="' + productName + '" style="width:' + columnW + '%">' + productName + '</div>'
                if (productTypeName == '预警信号') {
                    content += '<div style="width:  10.5%">' + new Date(item.pushTime).format('yyyy-MM-dd hh:mm') + '</div>'
                } else {
                    content += '<div style="width: ' + columnW + '%">' + new Date(item.makeTime).format('yyyy-MM-dd hh:mm') + '</div>'
                }
                content += '<div style="width:' + columnW + '%">' + makeUser + '</div>'
                if (productTypeName == '预警信号') {
                    content += '<div title="' + publishUnit + '" style="width:' + columnW + '%">' + publishUnit + '</div>'
                } else {
                    content += '<div style="width:' + columnW + '%">' + issuerName + '</div>'
                }
                if (productTypeName == '预警信号') {
                    content += '<div style="width:' + columnW + '%">' + publisher + '</div>'
                    content += '<div style="width:' + columnW + '%">' + issuerName + '</div>'
                    content += '<div style="width: 10.5%">' + new Date(item.publishDate).format('yyyy-MM-dd hh:mm') + '</div>'
                }
                content += '<div title="' + styleName + '" style="width: ' + columnW + '%">' + styleName + '</div>'
                content += '<div class="details-btn" style="width: ' + columnW + '%">详情</div>'
				if (productTypeName != '预警信号')
					content += '<div style="width:' + columnW + '%">' + success + '</div>'
                if (productTypeName == '预警信号' && min <= 10) {
                    timelyCount++
                    content += '<div style="width:' + columnW + '%">' + '及时' + '</div>'
                } else if (productTypeName == '预警信号') {
                    content += '<div style="width:' + columnW + '%">' + '不及时' + '</div>'
                }
                content += '</div>'
                var $content = $(content)
                $content.data('dataObj', item);
                domList.push($content);
            })
            if (productTypeName == '预警信号') {
                var timelyRate = ((timelyCount / data.length) * 100).toFixed(2)
                $(".timelyRate").text(timelyRate == 'NaN' ? '0%' : timelyRate + '%')
            } else {
                $(".publishTotal").text(publishTotal);
                var successRate = ((publishSuccessCount / publishTotal) * 100).toFixed(2);
                $(".successRate").text(successRate == 'NaN' ? '0%' : successRate +  '%');
            }
            $(".alarm-body").append(domList);
        },
        // word预览弹窗
        preview: function (url) {
            var that = this;
            $("#modal_word_Preview").remove()
            CafeJS.ModalBox({
                id: 'word_Preview',
                title: "word预览",
                width: 750,
                height: 760,
                m_top: 60,
                m_right: 200,
                hide: false,
                createSucc: function () {
                    that.wordPreview(url);
                }
            });
        },
        // 预览word
        wordPreview: function (url) {
            var $iframe = $(`<iframe style="width:100%;height:100%" src="/ioffice/officeView.do?path=${encodeURI(encodeURI(url))}"></iframe>`);
            $("#modal_word_Preview .modal-body").empty().append($iframe);
        },
        // 预警设施监控
        initFacilitiesData: function () {
            var $body = $(".facilities-body").empty();
            var param = {
                time: $("#datepicker .datepicker-date>span").text() + ':00',
                clientStyles: $("#facilitiesProduct").val()
            }
            var domList = [];
            loading.add('#modal_monitor');
            $.getJSON(api.internal.business.getFacilitiesData, param, function (res) {
                loading.remove();
                if (res.isSuccess) {
                    var data = res.data;
                    var onlineNumber = 0;
                    for (var i = 0; i < data.length; i++) {
                        var number = i + 1
                        var item = data[i];
                        if (item.status == '0') {
                            onlineNumber++
                        }
                        var $div = $(`<div class="facilities-item">
                        <div style="width: 10%">${number}</div>
                        <div style="width: 15%">${item.clientStyle}</div>
                        <div style="width: 15%">${item.clientID}</div>
                        <div style="width: 15%">${item.lon}</div>
                        <div style="width: 15%">${item.lat}</div>
                        <div style="width: 15%;color:${item.status == '0' ? '#333' : 'red'}">${item.status == '0' ? '正常' : '异常'}</div>
                        <div style="width: 15%">${item.updatedTime}</div></div>`);
                        domList.push($div);
                    }
                    $body.append(domList);
                    $(".deviceTotal").text(data.length);
                    $(".onlineNumber").text(onlineNumber);
                    var onlineRate = ((onlineNumber / data.length) * 100).toFixed(2)
                    $(".onlineRate").text(onlineRate == 'NaN' ? '0%' : onlineRate + '%');
                };
            })
        },
        // 其他监控弹窗
        initAddEventPop: function () {
            $("#modal_add_event").remove()
            CafeJS.ModalBox({
                id: 'add_event',
                title: "新增事件类型",
                width: 565,
                height: 260,
                m_top: 280,
                m_right: 370,
                hide: false,
                isBackdrop: true,
                url: api.internal.tpl.addEventPop,
                createSucc: function () {
                }
            });
        },
        // 其他监控数据
        getOtherMonitorData: function () {
            var that = this;
            var $body = $(".other-monitor-body").empty();
            var type = $("#eventType option:selected").text();
            var dept = $("#otherUnit option:selected").text();
            var param = {
                startTime: $("#startMonitorTime2").text() + ':00',
                endTime: $("#endMonitorTime2").text() + ':00',
                type: type == '全部' ? '' : type,
                dept: dept == '全部' ? '' : dept
            }
            loading.add('#modal_monitor');
            $.getJSON(api.internal.business.otherMonitorQuery, param, function (res) {
                loading.remove();
                var content = [];
                if (res.isSuccess && res.data.length > 0) {
                    $(".total-information span").text(res.data.length)
                    res.data.forEach(function (item, index) {
                        var fileName = item.filePath.split('/')
                        content.push(`<div class="details-item" data-id="${item.id}">
                                    <div style="width: 5%">${++index}</div>
                                    <div style="width: 11.5%">${new Date(item.monitorTime).format('yyyy-MM-dd hh:mm')}</div>
                                    <div style="width: 8.5%">${item.type}</div>
                                    <div style="width: 11.5%">${item.disaster || ''}</div>
                                    <div title="${item.monitorDesc || ''}" style="width: 11.5%">${item.monitorDesc || ''}</div>
                                    <div id="downLoadFile" title="${fileName[1]}" style="width: 11.5%">${fileName[1]}</div>
                                    <div style="width: 11.5%">${item.createUser}</div>
                                    <div style="width: 11.5%">${item.deptName}</div>
                                    <div style="width: 11.5%">${new Date(item.createTime).format('yyyy-MM-dd hh:mm')}</div>
                                    <div style="width: 6%"><a id="otherMonitorDel">删除</a></div>
                                    </div>`);
                    })
                    $body.append(content);
                } else {
                    alert('当前时间段无数据')
                }
            })
        },
        delOtherMonitor: function(id, row) {
            $.getJSON(api.internal.business.otherMonitorDel, {ids: id}, function (res) {
                if (res.isSuccess) {
                    row.remove();
                    alert('删除成功');
                }
            })
        },
        // 叫应监控弹窗
        initBidPop: function () {
            $("#modal_add_bid").remove()
            CafeJS.ModalBox({
                id: 'add_bid',
                title: "新增叫应",
                width: 565,
                height: 250,
                m_top: 260,
                m_right: 370,
                hide: false,
                isBackdrop: true,
                url: api.internal.tpl.addBidPop,
                createSucc: function () {
                }
            });
        },
        // 叫应详情
        initBidDetailsPop: function (item) {
            $("#modal_bid_details").remove()
            CafeJS.ModalBox({
                id: 'bid_details',
                title: "叫应详情",
                width: 600,
                height: 300,
                m_top: 275,
                m_right: 355,
                hide: false,
                isBackdrop: true,
                url: api.internal.tpl.bidDetailsPop,
                createSucc: function () {
                }
            });
            $("#modal_bid_details").data('item', item)
        },
        // 获取区域数据
        getUserOrgsData: function () {
            var $select = $("#unitSelect"), $productUnitSelect = $("#productUnitSelect"),
                $otherUnit = $("#otherUnit"), $processUnit = $("#processUnit");
            $.getJSON(api.internal.business.userOrgs, function (res) {
                if (res.isSuccess) {
                    var data = res.data;
                    for (var i = 0; i < data.length; i++) {
                        if (data[i].orgName.indexOf('灾防中心') == -1 && data[i].orgName.indexOf('天津市预警发布中心') == -1 && data[i].orgName.slice(data[i].orgName.length - 3) != '气象台') continue;
                        if (data[i].areaCode == '12') data[i].areaCode = '120000';
                        else if (data[i].areaCode == '120221') data[i].areaCode = '120117';
                        else if (data[i].areaCode == '120223') data[i].areaCode = '120118';
                        else if (data[i].areaCode == '120125') data[i].areaCode = '120119';
                        $select.append(`<option value="${data[i].areaCode}">${data[i].orgName}</option>`);
                        $productUnitSelect.append(`<option value="${data[i].areaCode}">${data[i].orgName}</option>`);
                        $otherUnit.append(`<option value="${data[i].areaCode}">${data[i].orgName}</option>`);
                        $processUnit.append(`<option value="${data[i].areaCode}">${data[i].orgName}</option>`);
                    }
                }
            });
        },
        // 查询叫应监控数据
        callMonitorQuery: function () {
            var $body = $(".bid-monitor-body").empty();
            var callResult = $("#statusType").val();
            var org = $("#unitSelect option:selected").text();
            if (org == '全部') {
                org = ''
            }
            var params = {
                startTime: $("#startMonitorTime3 .datepicker span").text() + ':00',
                endTime: $("#endMonitorTime3 .datepicker span").text() + ':00',
                callResult: callResult,
                org: org,
            }
            loading.add('#modal_monitor');
            $.getJSON(api.internal.business.callMonitorQuery, params, function (res) {
                loading.remove();
                if (res.isSuccess) {
                    var data = res.data;
                    var index = 0, totalSuccess = 0, bindTotal = 0, totalFail = 0;
                    for (var key in data) {
                        index = index + 1
                        var successRate = '';
                        var div = '<div class="bid-item">'
                        div += '<div style="width: 5%">' + index + '</div>'
                        div += '<div class="bid-detailsbtn" style="width: 22%">详情</div>'
                        div += '<div style="width: 12%">' + data[key].length + '</div>'
                        div += '<div style="width: 22%">' + key + '</div>'
                        data[key].forEach(function (item) {
                            if (item.callResult == '1') {
                                successRate++
                                totalSuccess++
                            } else {
                                totalFail++;
                            }
                            bindTotal++
                        })
                        div += '<div style="width: 19%">' + data[key][0].org + '</div>'
                        var success = ((successRate / data[key].length) * 100).toFixed(2)
                        div += '<div style="width: 10%">' + success + '%' + '</div>'
                        div += '<div style="width: 10%"><a id="bidMonitorDel">删除</a></div>'
                        div += '</div>'
                        var $div = $(div);
                        $div.data('item', data[key]);
                        $body.append($div);
                    }
                    $("#eventTotal").text(index);
                    $("#bindTotal").text(bindTotal);
                    $("#bindsuccess").text(totalSuccess);
                    if (totalSuccess == 0) {
                        $("#successRate").text(0 + '%');
                    } else {
                        if (callResult === 0) {
                            $("#successRate").text(((totalFail / bindTotal) * 100).toFixed(2) + '%');
                        } else {
                            $("#successRate").text(((totalSuccess / bindTotal) * 100).toFixed(2) + '%');
                        }
                    }
                }
            });
        },
        callMonitorDel: function(datalist, row) {
            let ids = [];
            datalist.forEach(function(item){
                ids.push(item.id);
            })
            $.getJSON(api.internal.business.callMonitorDel, {ids: ids.join(',')}, function (res) {
                if (res.isSuccess) {
                    row.remove();
                    alert('删除成功');
                }
            })
        },
        // 信息员监控区域
        getAreaSelectList: function (place) {
            var county = $("#areaSelect option:selected").text();
            var town = $("#townSelect option:selected").text();
            if (county == '全部') {
                county = 'all'
            }
            if (town == '全部') {
                town = 'all'
            }
            var params = {
                county: county,
                town: town,
            };
            var $select = ''
            if (place == 'area' && county != 'all') {
                $select = $("#townSelect").empty().append(`<option value="">全部</option>`);
            } else if (place == 'town' && town != 'all') {
                $select = $("#villageSelect").empty().append(`<option value="">全部</option>`);
            } else if (county != 'all' && town == 'all') {
                $select = $("#townSelect").empty().append(`<option value="">全部</option>`);
                $("#villageSelect").empty().append(`<option value="">全部</option>`);
            } else {
                $select = $("#areaSelect").empty().append(`<option value="">全部</option>`);
                $("#townSelect").empty().append(`<option value="">全部</option>`);
                $("#villageSelect").empty().append(`<option value="">全部</option>`);
            }
            $.getJSON(api.internal.business.getAreaSelectList, params, function (res) {
                if (res.isSuccess) {
                    var data = res.data;
                    data.forEach(function (item) {
                        var $option = $(`<option value="">${item}</option>`);
                        $select.append($option);
                    })
                }
            });
        },
        // 气象信息员监控
        weathermanDataQuery: function () {
            $(".weatherman-monitor-body").empty();
            var area = $("#areaSelect option:selected").text();
            var town = $("#townSelect option:selected").text();
            var village = $("#villageSelect option:selected").text();
            var params = {
                county: area == '全部' ? 'all' : area,
                town: town == '全部' ? 'all' : town,
                village: village == '全部' ? 'all' : village
            }
            loading.add('#modal_monitor');
            $.getJSON(api.internal.business.getMIInfoList, params, function (res) {
                loading.remove();
                var content = [];
                if (res.isSuccess && res.data.length > 0) {
                    $(".number span").text(res.data.length)
                    res.data.forEach(function (item, index) {
                        content.push(`<div class="weatherman-item">
                                    <div style="width: 8%">${++index}</div>
                                    <div style="width: 11.5%">${item.perName || ''}</div>
                                    <div style="width: 11.5%">${item.mobilePhone || ''}</div>
                                    <div style="width: 11.5%">${item.county || ''}</div>
                                    <div style="width: 11.5%">${item.town || ''}</div>
                                    <div style="width: 11.5%">${item.village || ''}</div>
                                    <div style="width: 11.5%">${item.reportUnitName || ''}</div>
                                    <div style="width: 11.5%">${new Date(item.updateTime).format('yyyy-MM-dd hh:mm')}</div>
                                    <div style="width: 11.5%">${item.updateUser || ''}</div>
                                    </div>`);
                    })
                    $(".weatherman-monitor-body").append(content);
                } else {
                    alert('当前时间段无数据');
                }
            });
        },
        threejkData: function () {
            var $body = $(".threejk-monitor-table table tbody").empty();
            var params = {
                startTime: $("#startThreejkTime2 .datepicker span").text() + ':00',
                endTime: $("#endThreejkTime2 .datepicker span").text() + ':00',
                current: 1,
                size: 10000000,
            };
            $.getJSON(api.internal.business.getThreejk, params, function (res) {
                loading.remove();
                var content = [];
                if (res.isSuccess && res.data.records.length > 0) {
                    let data = res.data.records;
                    data.sort(function (i, j) { return new Date(i.warnTime).getTime() - new Date(j.warnTime).getTime() });
                    data.forEach(function (item, index) {
                        content.push(`<tr>
                                    <td style="width: 10%">${++index}</td>
                                    <td style="width: 30%">${new Date(item.warnTime).format('yyyy-MM-dd hh:mm')}</td>
                                    <td style="width: 30%">${item.warnLevel || ''}</td>
                                    <td style="width: 30%">${item.warnType || ''}</td>
                                    </tr>`);
                    })
                    $body.append(content);
                } else {
                    alert('当前时间段无数据');
                }
            });
        },
        bindEvt: function () {
            var that = this;
            var interval = setInterval(function () {
                that.initFacilitiesData();
            }, 1000 * 60 * 30);
            $("#modal_monitor").find(".modal-title>span").click(function () {
                clearInterval(interval)
                if ($(this).hasClass('facilities-tab')) {
                    that.initFacilitiesData()
                } else if ($(this).hasClass('process-tab')) {
                    window.processMonitor.getProcessMonitorData();
                } else if ($(this).hasClass('bid-tab')) {
                    $("#bidQueryBtn").click();
                } else if ($(this).hasClass('weatherman-tab')) {
                    $("#weathermanQueryBtn").click();
                } else if ($(this).hasClass('othern-tab')) {
                    $("#queryBtn").click();
                } else if ($(this).hasClass('threejk-tab')) {
                    $("#threejkQueryBtn").click();
                }
                $(this).addClass("active").siblings().removeClass("active");
                $(".monitor-main>li").eq($(this).index()).show().siblings().hide();
            });
            $("#modal_monitor .close").click(function () {
                $("#modal_monitor").remove();
                $("#monitor").removeClass("active");
                clearInterval(interval)
            });
            $('.condition-item .submit').click(function () {
                that.buildTableHeader();
                that.getTableData();
            });
            $(".alarm-body").on('click', '.alarm-item .details-btn', function () {
                var data = $(this).parent().data('dataObj');
                that.publishDetailsPop(data);
            }).on('click', '.alarm-item .product-name', function () {
                var url = $(this).parent().data('dataObj').wordPath;
                that.preview(url);
            })
            $("#productType").change(function () {
                if ($(this).val() != 'yjxh') {
                    $(".timelyRate,#productUnitSelect").parent().hide();
                } else {
                    $(".timelyRate,#productUnitSelect").parent().show();
                }
                $(".alarm-body").empty();
                that.buildTableHeader();
            })
            $(".condition-item .submit").trigger("click");
            $("#queryBtn").click(function () {
                that.getOtherMonitorData();
            });
            $("#threejkQueryBtn").click(function () {
                that.threejkData();
            });
            $("#downLoadBtn").click(function () {
                $.exportExcel({
                    tableNm: '三级防御监控数据',
                    tableId: 'threejkTable',
                })
            })
            $("#addBtn").click(function () {
                that.initAddEventPop();
            })
            $("#bidAddBtn").click(function () {
                that.initBidPop();
            })
            $("#bidQueryBtn").click(function () {
                that.callMonitorQuery();
            })
            $(".bid-monitor-body").on('click', '.bid-detailsbtn', function () {
                var item = $(this).parent().data('item')
                that.initBidDetailsPop(item);
            }).on('click', '#bidMonitorDel', function(){
                let item = $(this).parent().parent().data('item');
                that.callMonitorDel(item, $(this).parent().parent());
            })
            $(".other-monitor-body").on('click', '#downLoadFile', function () {
                var id = $(this).parent().data('id')
                $("#fileName").attr('src', api.internal.business.downLoadFile + id)
            }).on('click', '#otherMonitorDel', function(){
                let id = $(this).parent().parent().data('id');
                that.delOtherMonitor(id, $(this).parent().parent());
            })
            $("#facilitiesQuery").click(function () {
                that.initFacilitiesData();
            })
            $("#weathermanQueryBtn").click(function () {
                that.weathermanDataQuery();
            })
            $("#areaSelect").change(function () {
                that.getAreaSelectList('area');
            })
            $("#townSelect").change(function () {
                that.getAreaSelectList('town');
            })
        },
        //弹出框内容
        alert: function (info) {
            $.dialogMaster({
                "type": 'tip',
                "info": info
            });
        },
    };
    if (typeof call === 'function') {
        window.monitor = main;
        call(main);
    }
})(function (main) {
    CafeJS.models(['datepicker'], function () {
        main.init();
    });
});